#!/bin/sh
#
# 统计文章字数，仅仅包括中文。
#
#
#

if [ $# -ne 1 ];then
        echo "Usage: $0 file.md"
	exit -1;
fi

name=`echo $1 | sed -e "s/.md//" | sed -e "s/.*_//g"`

echo `pwd` |grep "EN" >/dev/null

if [ $? -eq 0 ];then
	sed -e "s/ /\n/g" $1 |sed -e "s/\t/\n/g" |sed -e "s/\[/\n/g"|sed -e "s/\]/\n/g"| sed -e "s/[,.“””“?”#”!‘….(:?¯_]//g" |sed -e "/^$/d"|tr '[:upper:]' '[:lower:]' |sed -e "s/[;)]//g"|sed -e "s/^—//g"|sed -e "s/—$//g"|sed -e "s/[#”.’;?\!),\“]//g" |sed -e "s/[\&\*‘\(_]//g"|sed -e "s/[1234567890]//g"|sed -e "/^$/d" |sort |uniq -c  |sort -g  >wordcounter.md
else
	sed -e "s/[-–—_É［］·éèöã*à－▲çóō…;:.,()\n  1234567890+/•？＆?~﹔．'〕〔”’！：、abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZＱＫＪ{}#△〗〖“‘，。\"；《》（）  ]//g" $1  |sed -e "s/./&\n/g" |sed -e "/^　$/d" |sed -e "/^$/d"  |sort |uniq -c |sort -rg >wordcounter.md
fi

sed -e "/[-\/–·©=+〔']/d"  wordcounter.md >/tmp/tmp.md

mv /tmp/tmp.md wordcounter.md

exit
